#*-*coding=utf-8*-*
'''
Created on 21 janv. 2013

@author: tclain
'''
from instance.Errors import *

class Variable(object):
    '''
    Handle and stores a variable found in a template
    '''


    def __init__(self,rawstr):
        '''
        Constructor of the class Variable. It takes the raw string contained in the template and constructs a Variable Object 
        '''
        #Variable used in rawstr processing
        splitted = rawstr.split(":")
        if len(splitted) == 0:
            pass
        name = ""
        defaultValue = ""
        
        if len(splitted) == 0 :
            raise VariableError
        if len(splitted) == 1 :
            name = rawstr
        else:
            if len(splitted) == 2 :
                name = splitted[0]
                defaultValue = splitted[1]
        
        self._name = name
        self._defaultValue = defaultValue

    def hasDefaultValue(self):
        '''
        check if the variable has a default value, that is to say a value used if no explicit value is provided
        '''
        return self._defaultValue == ""
    def getName(self):
        '''
        getter of _name attribute
        '''
        return self._name
    def getDefaultValue(self):
        '''
        getter of _defaultValue attribute
        '''
        return self._defaultValue
    def __str__(self):
        return "name:" + self.getName() +";default"+self.getDefaultValue()
    



if __name__== "__main__":
    pass